class_name Save_point
extends Interactable

var is_activated: bool = false
var player_in_range: bool = false

func interact() -> void:
	super()
	activate_save_point()

func _process(delta):
	if player_in_range and Input.is_action_just_pressed("interact"):
		activate_save_point()

func _on_body_entered(body):
	if body is Player:
		player_in_range = true

func _on_body_exited(body):
	if body is Player:
		player_in_range = false

func activate_save_point() -> void:
	var player = get_tree().get_first_node_in_group("player")
	if !player:
		return
	
	player.restore_health()
	
	# 获取玩家并设置存档位置
	if !is_activated:
		is_activated = true
		player.set_respawn_position(global_position)
		print("存档点已激活 - 位置: ", global_position)
	else:
		print("生命值已恢复")
